/**
 * josn后端数据转对象
 * @param {String} strObj
 * @returns object
 */
function parse(strObj) {
    // let jsonObj = {}
    let JSONObj = {}
    let str = strObj.replace(/('|\s|{|})/g, '')
    let arr = str.split(',')
    arr.forEach((item) => {
        let temp = item.split(':')
        temp[0] = temp[0].replace(/("|\s)/g,'')
        temp[1] = temp[1].replace(/\s/g,'')

        if (temp[1] === 'true') {
            temp[1] = Boolean(temp[1])
        } else if (temp[1] === 'false') {
            temp[1] = Boolean(false)
        }else if (temp[1] === 'null'){
            temp[1] = null
        }else if( isNaN(Number(temp[1]))){
            temp[1] = temp[1].replace(/"/g,'')
        }else if( Number(temp[1])){
            temp[1] = Number(temp[1])
        }else if(temp[1] === '' || undefined){
            temp[1] = 'undefined'
        }
        JSONObj[temp[0]] = temp[1]
        
    })
    return JSONObj
}




/**
 * 将对象转换为后端JOSN数据
 * @param {Object} strObj
 * @returns string
 */
function stringify(obj){
    let arr = []
    for (let key in obj){
        var temp = obj[key]
        if( typeof temp === 'string'){
            temp = `"${obj[key]}"`
        }
        arr.push(`"${key}":"${temp}"`)
    }
    return `'{${arr.join()}}'`
}
console.log(stringify({a:1,b:true,c:true,d:false}));